#include "music.h"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <ctime>
#include <conio.h>
#include <windows.h>
#define M1 Beep(523,200);
#define M2 Beep(587,200);
#define M3 Beep(659,200);
#define M4 Beep(698,200);
#define M5 Beep(784,200);
#define M6 Beep(880,200);
#define M7 Beep(980,200);
#define qdo 262 
#define qre 294
#define qmi 330   //q
#define qfa 349
#define qso 392
#define qla 440
#define qsi 494
#define do 523
#define re 578
#define mi 659
#define fa 698
#define so 784
#define la 880
#define si 988
#define do1 1046
#define re1 1175
#define mi1 1318
#define fa1 1480
#define so1 1568
#define la1 1760
#define si1 1976
#define sqdo 277
#define sqre 311
#define sqfa 370
#define sqso 415
#define sqla 466
#define sdo 554
#define sre 622
#define sfa 740
#define sso 831
#define sla 932
#define sdo1 1046
#define sre1 1245
#define sfa1 1480
#define sso1 1661
#define sla1 1865
std::string s,tmp;int timelen=333; 
extern int achievement1[100];
void play_music(){
    for(int i=0;i<tmp.length();i++)
    	switch(tmp[i]){
				// case '1':M1;break;
				// case '2':M2;break;
				// case '3':M3;break;
				// case '4':M4;break;
				// case '5':M5;break;
				// case '6':M6;break;
				// case '7':M7;break;
				case '1':Beep(sdo1,timelen);break;
				case '2':Beep(sre1,timelen);break;
				case '3':Beep(sfa1,timelen);break;
				case '4':Beep(sso1,timelen);break;
				case '5':Beep(sla1,timelen);break;
				case '6':Beep(sdo,timelen);break;
				case '7':Beep(sre,timelen);break;
				case '8':Beep(sfa,timelen);break;
				case '9':Beep(sso,timelen);break;
				case '0':Beep(sla,timelen);break;
				case 'q':Beep(do1,timelen);break;
				case 'w':Beep(re1,timelen);break;
				case 'e':Beep(mi1,timelen);break;
				case 'r':Beep(fa1,timelen);break;
				case 't':Beep(so1,timelen);break;
				case 'y':Beep(la1,timelen);break;
				case 'u':Beep(si1,timelen);break;
				case 'i':Beep(sqdo,timelen);break;
				case 'o':Beep(sqre,timelen);break;
				case 'a':Beep(do,timelen);break;
				case 's':Beep(re,timelen);break;
				case 'd':Beep(mi,timelen);break;
				case 'f':Beep(fa,timelen);break;
				case 'g':Beep(so,timelen);break;
				case 'h':Beep(la,timelen);break;
				case 'j':Beep(si,timelen);break;
				case 'k':Beep(sqfa,timelen);break;
				case 'l':Beep(sqso,timelen);break;
				case 'z':Beep(qdo,timelen);break;
				case 'x':Beep(qre,timelen);break;
				case 'c':Beep(qmi,timelen);break;
				case 'v':Beep(qfa,timelen);break;
				case 'b':Beep(qso,timelen);break;
				case 'n':Beep(qla,timelen);break;
				case 'm':Beep(qsi,timelen);break;
				case ',':Beep(sqso,timelen);break;
                case ' ':Beep(0,300);break;
            }
}

void play_piano(){
	int i=0;
    char ch;
	while(1){
		if(kbhit())
		{
			ch=getche();
			s+=ch;
            switch(ch){
				// case '1':M1;break;
				// case '2':M2;break;
				// case '3':M3;break;
				// case '4':M4;break;
				// case '5':M5;break;
				// case '6':M6;break;
				// case '7':M7;break;
				case '1':Beep(sdo1,timelen);break;
				case '2':Beep(sre1,timelen);break;
				case '3':Beep(sfa1,timelen);break;
				case '4':Beep(sso1,timelen);break;
				case '5':Beep(sla1,timelen);break;
				case '6':Beep(sdo,timelen);break;
				case '7':Beep(sre,timelen);break;
				case '8':Beep(sfa,timelen);break;
				case '9':Beep(sso,timelen);break;
				case '0':Beep(sla,timelen);break;
				case 'q':Beep(do1,timelen);break;
				case 'w':Beep(re1,timelen);break;
				case 'e':Beep(mi1,timelen);break;
				case 'r':Beep(fa1,timelen);break;
				case 't':Beep(so1,timelen);break;
				case 'y':Beep(la1,timelen);break;
				case 'u':Beep(si1,timelen);break;
				case 'i':Beep(sqdo,timelen);break;
				case 'o':Beep(sqre,timelen);break;
				case 'a':Beep(do,timelen);break;
				case 's':Beep(re,timelen);break;
				case 'd':Beep(mi,timelen);break;
				case 'f':Beep(fa,timelen);break;
				case 'g':Beep(so,timelen);break;
				case 'h':Beep(la,timelen);break;
				case 'j':Beep(si,timelen);break;
				case 'k':Beep(sqfa,timelen);break;
				case 'l':Beep(sqso,timelen);break;
				case 'z':Beep(qdo,timelen);break;
				case 'x':Beep(qre,timelen);break;
				case 'c':Beep(qmi,timelen);break;
				case 'v':Beep(qfa,timelen);break;
				case 'b':Beep(qso,timelen);break;
				case 'n':Beep(qla,timelen);break;
				case 'm':Beep(qsi,timelen);break;
				case ',':Beep(sqso,timelen);break;
            }
			if(s.find("continue")!=std::string::npos){
				    printf("\n    /\\         /\\ \n");
					printf("   |   \\     /    \\\n");
					printf("  / .  |    /  .  |\n");
					printf(" |  .. \\    |  ..  |\n");
					printf("/  ....  |  |  ... /\n");
					printf("| -///**\\\\\\\\\\\\\\**-- |\n");
					printf("/// -- -_     _- --  \\\\\n");
					printf("|/\\\\__fu_|   |_tao_/   |\n");
					printf("\\\\/      __-__        /  - -Yan xu continue\n");
    				printf("||       \\__/       /| ");
					printf("==========================\n");
                    s="";
			}
            if(s.find("exit")!=std::string::npos){
                s="";
                printf("确认退出？y/n");
                char c=getche();
                if(c=='y'){
                    system("cls");
                    return;
                }else {

                    continue;
                }
            }
            if(s.find("retrq")!=std::string::npos){
                Beep(0,5000);
                tmp="r  etrqe r  etr qer  erewq  r eree y";
                play_music();
                s="";
				printf("/n获得成就: 大梦叠音,似曾相识\n");
				achievement1[3]=1;
				system("pause");
				printf("\n");
				// system("cls");
            }
		}
	}
}
//bbbbhhjhg fdfghfhjhg hjq qwerewqhjqqqgwewqwer
// int main(){
// 	tmp="bbbhjhgfdfg  hfhjhg  hjw  w wertre  wqwe  jhg  qjhgfddfg  dgfd  dgfd  dgfd  dgfdfghjhgf  ghjqwqj jhgffghqcvbb ";
// 	play_music();
// 	system("pause");
// 	int i=0;
//     char ch;
// 	while(1){
// 		if(kbhit())
// 		{
// 			ch=getche();
// 			s+=ch;
//             switch(ch){
// 				// case '1':M1;break;
// 				// case '2':M2;break;
// 				// case '3':M3;break;
// 				// case '4':M4;break;
// 				// case '5':M5;break;
// 				// case '6':M6;break;
// 				// case '7':M7;break;
// 				case '1':Beep(sdo1,timelen);break;
// 				case '2':Beep(sre1,timelen);break;
// 				case '3':Beep(sfa1,timelen);break;
// 				case '4':Beep(sso1,timelen);break;
// 				case '5':Beep(sla1,timelen);break;
// 				case '6':Beep(sdo,timelen);break;
// 				case '7':Beep(sre,timelen);break;
// 				case '8':Beep(sfa,timelen);break;
// 				case '9':Beep(sso,timelen);break;
// 				case "0":Beep(sla,timelen);break;
// 				case 'q':Beep(do1,timelen);break;
// 				case 'w':Beep(re1,timelen);break;
// 				case 'e':Beep(mi1,timelen);break;
// 				case 'r':Beep(fa1,timelen);break;
// 				case 't':Beep(so1,timelen);break;
// 				case 'y':Beep(la1,timelen);break;
// 				case 'u':Beep(si1,timelen);break;
// 				case 'i':Beep(sqdo,timelen);break;
// 				case 'o':Beep(sqre,timelen);break;
// 				case 'a':Beep(do,timelen);break;
// 				case 's':Beep(re,timelen);break;
// 				case 'd':Beep(mi,timelen);break;
// 				case 'f':Beep(fa,timelen);break;
// 				case 'g':Beep(so,timelen);break;
// 				case 'h':Beep(la,timelen);break;
// 				case 'j':Beep(si,timelen);break;
// 				case 'k':Beep(sqfa,timelen);break;
// 				case 'l':Beep(sqso,timelen);break;
// 				case 'z':Beep(qdo,timelen);break;
// 				case 'x':Beep(qre,timelen);break;
// 				case 'c':Beep(qmi,timelen);break;
// 				case 'v':Beep(qfa,timelen);break;
// 				case 'b':Beep(qso,timelen);break;
// 				case 'n':Beep(qla,timelen);break;
// 				case 'm':Beep(qsi,timelen);break;
// 				case ',':Beep(sqso,timelen);break;
//             }
// 		}
// 	}
// 	return 0;
// }
